// 写法二
addEventListener('message', function (e) {
    console.log(JSON.stringify(e.data))
    ajax(e.data.a, e.data.b).then(r => {
        this.postMessage(r);
    }).catch(err => {
        this.postMessage(err);
    });
}, false);

function ajax(a, b) {
    return new Promise((resolve, reject) => {
        var xhr = new XMLHttpRequest();
        // 指定通信过程中状态改变时的回调函数 
        xhr.onreadystatechange = function () {
            // 通信成功时，状态值为4
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    console.log(xhr.responseText);
                    resolve(xhr.responseText);
                } else {
                    console.log(xhr.statusText);
                    reject(xhr.statusText);
                }
            }
        };
        xhr.onerror = function (e) {
            console.log(xhr.statusText);
            reject(xhr.statusText);
        };
        xhr.open('GET', `http://192.168.1.206:3000/?a=${a}&b=${b}`, true);
        // 发送HTTP请求 
        xhr.send(null);
    });
}